{extend name="layout/layout" /}

{block name="pagecss"}
<link href="__STATIC__/plugins/ueditor/ueditor.css" rel="stylesheet" type="text/css" />
<style>
    #edui1_imagescale{display:none !important;}  /*点击上传的图片后出现的拉伸边框*/
    .edui-editor-bottomContainer{display: none;}
</style>
{/block}

{block name="content"}
<div class="row">
    <div class="col-md-12">
        <div class="portlet light">
            <div class="portlet-title">
                <div class="caption">
                    <i class="icon-share font-dark"></i>
                    <span class="caption-subject font-dark bold uppercase"> 编辑村子</span>
                </div>
                <div class="actions">
                    <a class="btn btn-circle btn-icon-only btn-default fullscreen" href="javascript:;" data-original-title="" title=""> </a>
                </div>
            </div>
            <div class="portlet-body">
                <form action="{:url('admin/'.strtolower($model).'/editPost')}" class="form-horizontal" method="post" enctype="multipart/form-data">
                    <div class="form-body">
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        所在地
                                        <span class="required">*</span>
                                    </label>
                                    <div class="col-md-9">
                                        <div class="form-inline">
                                            <p class="form-control-static">{$area}</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        村子名称
                                        <span class="required">*</span>
                                    </label>
                                    <div class="col-md-9">
                                        <input type="text" class="form-control" id="name" data-required="1" name="name" maxlength="80" value="{$info.name}">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        地址<span class="required">*</span>
                                    </label>
                                    <div class="col-md-9">
                                        <input type="text" id="address" value="{$info.address|default=''}" class="form-control input-large margin-bottom" name="address" placeholder="请输入详细地址，带省市">
                                        <input type="text" id="add-text1" style="display:none" value="{$info.address|default=''}" class="form-control input-large" name="addressGeo">
                                        <br />
                                        <div style="width:100%;height:300px;" id="map_container"></div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        封面图
                                    </label>
                                    <div class="col-md-9">
                                        <div id="upload-image">
                                            <span id="upload-btn" data-multi="false">
                                                <input type="hidden" class="form-control" id="coverImg"  name="coverImg" value="{$info.imgUrl}">
                                                <img src="{$info.imgUrl|default='__STATIC__/admin/img/default.png'}" alt="图片上传" style="width: 100px;height: 100px;" />
                                            </span>
                                        </div>
                                        <span class="help-block"> (建议尺寸：750*500) </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        村子图片
                                    </label>
                                    <div class="col-md-9">
                                        <div id="cover-image">
                                            {foreach name="imagesList" item="images"}
                                            <span class="multi-image">
                                                <input type="hidden" name="imgIds" value="{$images.id}">
                                                <input type="hidden" name="imgUrl" value="{$images.imgUrl}">
                                                <img class="exist-image" src="{$images.imgUrl}" alt="">
                                                <img class="del" src="__STATIC__/pages/image/del.png" alt="">
                                            </span>
                                            {/foreach}
                                            <span id="upload-cover-btn" data-multi="true" data-field="imgUrl">
                                                <!--<input type="hidden" class="form-control" id="imgUrl" data-required="1" name="imgUrl" value="">-->
                                                <img src="__STATIC__/admin/img/default.png" alt="图片上传" style="width: 100px;height: 100px;" />
                                            </span>
                                        </div>
                                        <span class="help-block"> (建议尺寸：750*457) </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        联系人
                                    </label>
                                    <div class="col-md-9">
                                        <input type="text" class="form-control" id="phone" data-required="1" name="personName" value="{$info.personName}">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        联系电话
                                    </label>
                                    <div class="col-md-9">
                                        <input type="text" onkeyup="if(this.value.length==1){this.value=this.value.replace(/[^0-9(\-)]/g,'')}else{this.value=this.value.replace(/[^0-9(\-)]/g,'')}"  class="form-control" id="phone" data-required="1" name="phone" value="{$info.phone}">
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <label class="control-label col-md-3">
                                        村介绍
                                    </label>
                                    <div class="col-md-9">
                                        <!--<textarea class="form-control" name="introduction" rows="3" maxlength="800">{$info.introduction}</textarea>
                                        <span class="help-block"> 最多800字符 </span>-->
                                        <script id="container" name="introduction" type="text/plain"></script>
                                        <div id="pro_txt" class="hidden">{$info.introduction}</div>

                                        <div id="btn-uploader1">
                                            <a id="pickfiles1" href="javascript:void 0;"></a>
                                        </div>
                                        <a id="pickfilesforarticleRadio" href="javascript:;"></a>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <input type="hidden" name="id" value="{$info.id}">

                        <hr />
                        <div class="row">
                            <div class="form-actions">
                                <div class="col-md-offset-2 col-md-10">
                                    <button type="button" id="form-submit" class="btn blue save-btn">
                                        保存 <i class="fa fa-floppy-o"></i>
                                    </button>
                                    <button type="button" class="btn default" onclick="history.go(-1);">
                                        返回 <i class="fa fa-mail-forward"></i>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<input type="hidden" class="token_url" value="{:url('admin/Image/token')}">
<input type="hidden" class="record_url" value="{:url('admin/Image/record')}">
<input type="hidden" class="delimage_url" value="{:url('admin/Image/delete')}">
{/block}

{block name="pagescript"}
<script type="text/javascript" src="__STATIC__/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="__STATIC__/plugins/ueditor/ueditor.all.js"></script>
<script src="__STATIC__/admin/js/qiniu/plupload.full.min.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniu.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/custom.js" type="text/javascript"></script>
<script src="__STATIC__/admin/js/qiniu/qiniuConfig.js" type="text/javascript"></script>
<script src="__STATIC__/admin/pages/js/ueditor.js" type="text/javascript"></script>
<script src="__STATIC__/admin/pages/js/uploadfile.js" type="text/javascript"></script>
<script src="https://api.map.baidu.com/api?v=2.0&ak=07E2669c3b77a0793274952ba61cd8b8&s=1" type="text/javascript"></script>
<script src="__STATIC__/admin/pages/js/villages.js" type="text/javascript"></script>
<script>
    var posturl = "{:url('admin/'.strtolower($model).'/editPost')}";
    var areaurl = "{:url('admin/layer/getCounty')}";

    function getList2(id,type) {
        $('.'+type).html('');
        var name = '';
        var selectId = 0;
        if(type == 'xian') {
            name = '所有区县';
            selectId = {$info.xianId};
        } else if(type=='town') {
            name = '所有乡镇';
            selectId = {$info.townId};
        }
        if(id != 0) {
            $.ajax({
                url : areaurl,
                type : 'post',
                dataType : 'json',
                contentType : "application/json; charset=utf-8",
                data : JSON.stringify({'id':id}),
            }).done(function(data) {
                var $item = "<option value='0'>"+name+"</option>";
                for (let i in data){
                    $item += "<option  value='"+i+"'";
                    if(selectId == i){
                        $item += " selected ";
                    }
                    $item += " '>"+data[i]+"</option>";
                }
                $('.'+type).append($item);           
            });
        } else {
            $('.'+type).append("<option value='0'>"+name+"</option>");
        }
    }
    getList2({$info.cityId},'xian');
    getList2({$info.xianId},'town');

</script>
{/block}